﻿namespace SpikingVisualisationRLib

open RProvider
open RProvider.``base``
open RProvider.graphics
open SpikingAnalyticsLib

[<AbstractClass; Sealed>]
type SynapticWeightVisualisation () =

    /// Show a histogram of synaptic weights (both excitatory and inhibitory)
    static member ShowWeightSampleHistogram(network:CrossbarNetwork, numSamples) =
        let sampleSet = CrossbarNetwork.GenerateSampleIndices(numSamples, 0, network.TotalConnections)
        let sample =
            network.SampleConnections(sampleSet)
            |> Array.map (fun connection -> connection.Weight)

        namedParams [
            "x", box sample;
        ]
        |> R.hist |> ignore

    /// Show a histogram of excitatory synaptic weights
    static member ShowExcitatoryWeightSampleHistogram(network:CrossbarNetwork, numSamples) =
        let sampleSet = CrossbarNetwork.GenerateSampleIndices(numSamples, 0, network.ExcitatoryConnections)
        let sample =
            network.SampleConnections(sampleSet)
            |> Array.map (fun connection -> connection.Weight)

        namedParams [
            "x", box sample;
        ]
        |> R.hist |> ignore

    /// Show a histogram of inhibitory synaptic weights
    static member ShowInhibitoryWeightSampleHistogram(network:CrossbarNetwork, numSamples) =
        let sampleSet = CrossbarNetwork.GenerateSampleIndices(numSamples, network.ExcitatoryConnections, network.TotalConnections)
        let sample =
            network.SampleConnections(sampleSet)
            |> Array.map (fun connection -> connection.Weight)

        namedParams [
            "x", box sample;
        ]
        |> R.hist |> ignore
